package vn.edu.saigontech.ncms.model.comparator;

import java.util.Comparator;

import vn.edu.saigontech.ncms.model.info.OfferingMember;

public class OfferingMemberComparator implements Comparator<OfferingMember> {

	@Override
	public int compare(OfferingMember member1, OfferingMember member2) {
		if (member1.getGrade() != null && member2.getGrade() != null) {
			Double score1 = member1.getTotalScore1();
			Double score2 = member2.getTotalScore1();
			if (score1.equals(score2)) {
				int absent1 = member1.getAbsentAttendances().size();
				int absent2 = member2.getAbsentAttendances().size();
				return absent1 - absent2;
			}
			return score2.compareTo(score1);
		}
		return 0;
	}
}